package com.github.boluo1230.wechat.util;


import java.util.ArrayList;
import java.util.List;

public class PageHelperUtil {

    public static <E> List<E> subList(List<E> list, int pageNo, int pageSize) {
        int size = list.size();
        int from = (pageNo - 1) * pageSize <= 0 ? 0 : (pageNo - 1) * pageSize;
        int to = pageNo * pageSize >= size ? size : pageNo * pageSize;

        if (from >= size) {
            return new ArrayList<>();
        }
        return list.subList(from, to);
    }
}
